/*
 * @Author: 郭招娣 10615594+guo-zhaodi@user.noreply.gitee.com
 * @Date: 2022-09-12 10:40:26
 * @LastEditors: 郭招娣 10615594+guo-zhaodi@user.noreply.gitee.com
 * @LastEditTime: 2022-09-20 14:09:38
 * @FilePath: \郭招娣\hou\app\controller\home.js
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
/*
 * @Author: 郭招娣 10615594+guo-zhaodi@user.noreply.gitee.com
 * @Date: 2022-09-12 10:40:26
 * @LastEditors: 郭招娣 10615594+guo-zhaodi@user.noreply.gitee.com
 * @LastEditTime: 2022-09-14 11:52:32
 * @FilePath: \郭招娣\hou\app\controller\home.js
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
'use strict';

const Controller = require('egg').Controller;
class SystemController extends Controller {

    // 更改密码
    async update() {
        const { ctx } = this;
        const { oldPass,newPass,id } = ctx.request.body;
        const result = await this.app.mysql.get('user', { password:oldPass  });
        if (result) {
            // 原密码正确
            const row = {
                
                password:newPass,
            };

            const options = {
                where: {
                    id,
                    // oldPass,
                }
            };
            const list = await this.app.mysql.update('user', row, options);
            if(list){
                ctx.body={
                    code:200,
                    msg:'更改成功'
                }
            } else {
                ctx.body = {
                    code: 500,
                    msg: '更改失败'
                }
            }
        }
       
    }
}

module.exports = SystemController;
